<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.resExpectedOccupation" placeholder="岗位名称" clearable></el-input>
      </el-form-item>
       <el-form-item>
        <template>
              <el-select v-model="dataForm.myResState" placeholder="请选择">
                <el-option
                  v-for="item in options1"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </template>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button  type="primary" @click="addHandle()">录入简历</el-button>
      </el-form-item>
       
      
        <!-- <el-button v-if="isAuth('generator:resume:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button> -->
      
    </el-form>
    <div v-for="data of dataList" :key="data.resId">
    <div class="main" >
        <el-row >
          <el-col :span="8">
            <div style="margin-top:20px">
              <p>{{data.resName}}&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;{{data.resAge}}岁&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;{{data.resGender}}</p>
              <p>{{data.resExpectedOccupation}}&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;{{data.resExpectedArea}}  </p>
              <p>{{data.resWorkYear}}&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;{{data.resExpectedSalary}}</p>
            </div>
          </el-col>
          <el-col :span="6">
            <div style="margin-top:20px">
              <p>{{data.resEducation}}&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;{{data.resMajor}}</p>
              <p>{{data.resOutCollege}}毕业于{{data.resCollege}} </p>
              <p>录入时间：{{data.resTime}}</p>
            </div>
          </el-col>
          <el-col :span="5">
            <div style="margin-top:40px">
              
             <p>简历状态:
               <span v-if="data.myResState==0">预约</span>
               <span v-if="data.myResState==1">储备</span>
               <span v-if="data.myResState==2">入职</span>
               <span v-if="data.myResState==3">无效</span>
               <span v-if="data.myResState==4">未处理 &nbsp;&nbsp;&nbsp;&nbsp;
                  <el-button   @click="interviewHandle(data.resId)">预约</el-button>
               </span>
             </p>
              
            </div>
          </el-col>

          <el-col :span="3">
            <div style="margin-top:40px">
              
              <el-button type="primary"  @click="shareHandle(data.resId,data.myResState,data.resHrid,data.userId,data.resShare)">分享</el-button>
              
            </div>

          </el-col>
          <el-col :span="2">
            <div style="margin-top:40px">
              
              <el-button type="text" size="small" @click="infoHandle(data.resId)">简历详情</el-button>
              
            </div>
          </el-col>
        </el-row>
      
    </div>
</div>




   
    <!-- 弹窗, 新增 -->
    <add-or-update v-if="addVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <info v-if="infoVisible" ref="info" @refreshDataList="getDataList"></info>
    <interview-add v-if="interviewAddVisible" ref="add" @refreshDataList="getDataList"></interview-add>
  </div>
</template>

<script>
  import AddOrUpdate from './resume-add-or-update'
  import Info from './resume-info'
  import InterviewAdd from './interview-add'
  export default {
    data () {
      return {
        // show:true,
        dataForm: {
          key: ''
        },
        
        dataList: [],
        // pageIndex: 1,
        // pageSize: 10,
        // totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addVisible: false,
        infoVisible:false,
        interviewAddVisible:false,
         options1: [{
          value: 0,
          label: '预约'
        }, {
          value: 1,
          label: '储备'
        }, {
          value: 2,
          label: '入职'
        }, {
          value: 3,
          label: '无效'
        }
        , {
          value: null,
          label: '全部'
        }],
      }
    },
    components: {
      AddOrUpdate,
      Info,
      InterviewAdd
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        // console.log(this.dataForm.myResState)
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/generator/resume/myList'),
          method: 'get',
          params: this.$http.adornParams({
            // 'page': this.pageIndex,
            // 'limit': this.pageSize,
            'resExpectedOccupation': this.dataForm.resExpectedOccupation,
            'myResState': this.dataForm.myResState
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.list
            // this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            // this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // // 每页数
      // sizeChangeHandle (val) {
      //   this.pageSize = val
      //   this.pageIndex = 1
      //   this.getDataList()
      // },
      // // 当前页
      // currentChangeHandle (val) {
      //   this.pageIndex = val
      //   this.getDataList()
      // },
      // 多选
      // selectionChangeHandle (val) {
      //   this.dataListSelections = val
      // },
      // 新增 
      addHandle () {
        this.addVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init()
        })
      },
      
     
      //分享简历
      shareHandle(id,state,resHrid,userId,share){
        console.log(userId)


        if(state!==1){
            this.$alert('简历状态不是储备,不允许分享！', '提示', {
            confirmButtonText: '确定',
        });
        }else if(resHrid!==userId){
             this.$alert('您不是该简历录入人,不允许分享！', '提示', {
            confirmButtonText: '确定',
        });
        }else if(share!==1){
            this.$alert('该简历所有人未允许分享,不允许分享！', '提示', {
            confirmButtonText: '确定',
        });
        }else{
            this.$confirm('是否分享简历?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'info '
        }).then(() => {
           this.$http({
              url: this.$http.adornUrl(`/generator/share/add`),
              method: 'post',
              params: this.$http.adornParams({
                'resId': id,
                'userId': userId
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '分享成功',
                  type: 'success',
                  duration: 1500,
                  
                })
                
              } else {
                this.$message.error(data.msg)
              }
            });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消分享'
          });          
        });

        }
      },

      //添加预约
      interviewHandle(id){
        this.interviewAddVisible = true
        this.$nextTick(() => {
          this.$refs.add.init(id)
          })
      },
      //简历详情
      infoHandle(id){
        
        this.infoVisible = true
        this.$nextTick(() => {
          this.$refs.info.init(id)
          })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.resId
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/generator/resume/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>
<style>
.main {
  border: 1px dashed paleturquoise;
  width: 100%;
  height: 120px;
  text-align: center;
  margin: 10px auto;

}
</style>

